<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="layui/css/layui.css">

</head>

<body>
    <div class="layui-form-item">
        <label class="layui-form-label">偶数</label>
        <div class="layui-input-block">
            <input type="text" id="ouShu" placeholder="请输入标题" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">奇数</label>
        <div class="layui-input-block">
            <input type="text" id="jiShu" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" onclick="get()"><i class="layui-icon layui-icon-search"></i>获取数据</button>
        </div>
    </div>
    <script src="layui/layui.js"></script>
    <script>
        // 计算100以内奇数之和，偶数之和
        function get(){
            var ouShu = 0;
            var jiShu = 0;
            for (let index = 1; index <= 100; index++) {
                if(index % 2 == 0){
                    ouShu += index;
                }else{
                    jiShu += index;
                }
                
            }

            document.getElementById("ouShu").value = ouShu;
            document.getElementById("jiShu").value = jiShu;
        }
    </script>
</body>

</html>